<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.main.PicClient"%>
<%@page import="com.util.XMLExactractor"%><html>


<%
	String isFirst=request.getParameter("first");
	if(isFirst==null){
		isFirst="true";
	}
	String keyword = request.getParameter( "keywrd" );
	//String text=request.getParameter("rawText");
	String apikey=(String)session.getAttribute("apikey");
	String userID=(String)session.getAttribute("uid");
	System.out.println(userID);
	System.out.println(keyword);
	System.out.println(apikey);
	//String keyword = request.getParameter( "keywrd" );
	System.out.println(keyword);
		String domain=request.getParameter( "domain" );
		String title=request.getParameter( "title" );
		String subTitle=request.getParameter( "subtitle" );
		//String apiKey=session.getAttribute("apiKey").toString();
		//String userID=session.getAttribute("userID").toString();
	//String servicename=(String)session.getAttribute("service");
	

%>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>



</head>

<body >
<script type="text/javascript" src="jquery.js"></script>
<SCRIPT type="text/javascript">
parent.myobject.myproperty;
var keyword;
var title;
var subtitle;
var domain;
var userID;
var apiKey;
</SCRIPT>

<script type="text/javascript">
function savetoDB(){
	document.location.href="http://localhost:8080/picClient/FeedBack?url="+"hhbbnbn";
}
</script>
<script type="text/javascript">
function loadXML()
{	
	if (window.XMLHttpRequest)
	  {//document.write("Oin creating");
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function(){

		if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
			xmlstr=xmlhttp.responseText;
		    
		    if (window.DOMParser)
		 	 {
		 	
		  		parser=new DOMParser();
		  		xmlDoc=parser.parseFromString(xmlstr,"text/xml");
		  	 }
			else // Internet Explorer
		  	 {
		  	
		  		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  		xmlDoc.async="false";
		  		xmlDoc.loadXML(xmlstr);
		  	 }
		    try{
		        
		    	x=xmlDoc.getElementsByTagName("url");
		    	 ranks=xmlDoc.getElementsByTagName("rank");
		    	 y=x[0];
		    		z=x[0].childNodes[0].nodeValue;
		        	str="<tr>";
		       	for(var i=0;i<x.length;i=i+1){
		       		var temprank=ranks[i].childNodes[0].nodeValue;
		       		var checkBox;
		       		if(temprank==null || temprank=="null"){
		       			checkBox="";
			       		temprank="";
		       		}
		       		else{
			       		temprank="Rank="+temprank;
			       		checkBox="<br><INPUT TYPE=CHECKBOX NAME=\"check\" value=\"Irrelevent Image\">";
			       		
		       		}
		       		if((i%5)==0 && (i!=0)){
		    			str=str+"</tr><tr><td><img src="+"\""+x[i].childNodes[0].nodeValue+"\""+"onclick="+"\""+"saveToDB("+"'"+x[i].childNodes[0].nodeValue+"'"+")"+"\""+    " alt="+"\"picSEEK\""+ " width="+"\"200\""+" height="+"\"200\""+" /><br>"+temprank+"</br>"+checkBox+"</td>";
		    		}
		    		else{
		    			str=str+"<td><img src="+"\""+x[i].childNodes[0].nodeValue+"\""+" onclick="+"\""+"saveToDB("+"'"+x[i].childNodes[0].nodeValue+"'"+")"+"\""+" alt="+"\"picSEEK\""+ " width="+"\"200\""+" height="+"\"200\""+" /><br>"+temprank+"</br>"+checkBox+"</td>";
		    		}
		    	}
		       	keyword="<%=keyword%>";
		    	title="<%=title%>";
		    	subtitle="<%=subTitle%>";
		    	domain="<%=domain%>";
		    	userID="<%=userID%>";
		    	apiKey="<%=apikey%>";
		    	
		      	str=str+"</tr><tr><td>"+"<li id="+"\""+"active"+"\""+"><a href="+"\""+"http://localhost:8080/picClient/result.jsp?keywrd="+keyword+"&domain="+domain+"&title="+title+"&subtitle="+subtitle+"&userID="+userID+"&apikey="+apiKey+"&requestID=25&first=false"+"\""+"id="+"\""+"current"+"\""+">Next</a></li>"+"</td></tr></table>";
		       	$("#tid").html(str);
		        }catch(err){
		    		//alert(err.description);
		    	}
	    }
	  

	}
	var randomnumber=Math.floor(Math.random()*11);
	var first="<%=isFirst%>";
	keyword="<%=keyword%>";
	title="<%=title%>";
	subtitle="<%=subTitle%>";
	domain="<%=domain%>";
	userID="<%=userID%>";
	apiKey="<%=apikey%>";
	document.write("random="+randomnumber);
	document.write("-"+keyword+"-"+domain+"-"+userID+"-"+apiKey+"-"+title+"-"+subtitle+"-");
	xmlhttp.open("GET","http://localhost:8080/picClient/SearchImagesWCTXvars?keyword="+keyword+"&domain="+domain+"&title="+title+"&subTitle="+subtitle+"&userID="+userID+"&apiKey="+apiKey+"&requestID=25&ran="+randomnumber+"&first="+first,true);
	xmlhttp.send();
	
}

</script>

<div id="templatemo_container">
<div id="header_Result">
<div id="templatemo_content">
<div id="templatemo_top">
<div class="templatemo_center">
<div id="templatemo_site_title"></div>
<br />
<!-- <form method="POST" action="">
<div class="frmText">
<table border="0">
	<tr>
		<td>Search For:</td>
		<td><input type="text" value="<%=keyword %>" id="searchFor" name="search"
			disabled="true" size="40" /></td>
		<td><input type="submit" value="Search" disabled="true" /></td>
	</tr>
</table>
</div>
<br />

</form>-->
</div>
</div>
</div>
</div>

<div class="imgSet">
<div align="left" >
<h3>picSEEK Image Recommendation</h3>
</div>
<table border="0" id="tid">
 <tr><td>   </td>   </tr> 
</table>
<script type="text/javascript">
loadXML();
</script>

</div>


<div id="templatemo_footer">
<div class="footer_left"></div>
<div class="footer_dot"></div>
<div class="footer_right"></div>
</div>
</div>
</body>
</html>
